package com.alipay.app.groupmeal.standard.ui.c.abcp;

import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;

import com.alipay.app.groupmeal.standard.R;
import com.alipay.app.groupmeal.standard.base.BaseMVCActivity;
import com.alipay.app.groupmeal.standard.ui.b.function.CardPre;
import com.alipay.sdk.abcphaima.AbcpHM;
import com.alipay.sdk.abcphaima.AbcpQuotaAuthPage;

public class CQuotaAuthActivity extends BaseMVCActivity {

    public static CQuotaAuthActivity quotaAuthActivity = null;

    private CardPre cardPre;


    public static void startActAbcp(Activity activity) {

        Intent intent = new Intent(activity, CQuotaAuthActivity.class);
        activity.startActivity(intent);
    }

    @Override
    public boolean onKeyEventBack(KeyEvent event) {
        finish();
        return super.onKeyEventBack(event);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_transparent;
    }

    @Override
    protected void initView() {
        quotaAuthActivity = this;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void dissmissPresnetation() {
        if (cardPre != null) {
            cardPre.dismiss();
        }
        AbcpQuotaAuthPage.close(new AbcpHM.AbcpLoadingCallback() {
            @Override
            public void onSuccess(String tradeNo, String sessionId, String alipayUid) {

            }

            @Override
            public void onFail(String code, String msg) {

            }

            @Override
            public void onEvent(String sessionId) {

            }
        });
    }

    @Override
    public void initPresentation() {
        super.initPresentation();
        if (mDisplay != null) {
            cardPre = new CardPre(this, mDisplay);
            registerPresentation(cardPre);
            showPresentation(cardPre);
            cardPre.shows();
        }
        //abcp刷脸服务
        abcp();
    }

    private void abcp() {
        AbcpQuotaAuthPage.showPage(new AbcpHM.AbcpScanFaceCallback() {


            @Override
            public void onSuccess(boolean isFace, String authCode, String barCode, String tradeNo, String sessionId, String alipayUid) {
                System.out.println("成功");
            }

            @Override
            public void onFail(String code, String msg) {
                System.out.println("code:" + code + "    msg:" + msg);
                if ("1003".equals(code)) {
                    finish();
                }
            }

            @Override
            public void onEvent(String sessionId) {

            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("关闭");
        quotaAuthActivity = null;
    }
}
